﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace PCCS.Management
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string adminName = txtAdminName.Text.Trim();
            string password = txtPassword.Text.Trim();
            Admin admin = AdminManager.LoginByAdminName(adminName);
            AdminLog log = new AdminLog();
            log.AdminName = adminName;
            log.LogTime = DateTime.Now;
            if (admin.PassWord != null)
            {
                if (admin.PassWord.Equals(password))
                {
                    Session["admin"] = admin.AdminID;
                    log.LogDesc = "管理员成功登录平台。";
                    AdminLogManager.AddAdminLog(log);
                    Response.Redirect("index.aspx");
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "aaa", "alert('用户名或密码错误。')", true);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "aaa", "alert('用户名不存在。')", true);
            }
        }

    }
}
